#include <iostream>
#include <exception>

using namespace std;

template<class T>
class MyNode{
public:
	T value;
	MyNode<T> * next;
};

template<class T>
class MyStack{
private:
	MyNode<T> * _stack;
	int _size;
public:
	MyStack() : _stack(NULL), _size(0){
	}

	~MyStack(){
		delete [] _stack;
		_size = 0;
	}

	int size(){
		return _size;
	}

	int push(T elem){
		MyNode<T> * new_elem = new MyNode<T>;
		if (new_elem == NULL)
			return -1;
		new_elem->value = elem;
		new_elem->next = _stack;
		_stack = new_elem;
		_size++;
		return 0;
	}

	T pop(){
		try{
			if (_size == 0)
				throw "The Stack is empty";
			T val = _stack->value;
			MyNode<T> * tmp = _stack;
			_stack = _stack->next;
			delete tmp;
			_size--;
			return val;
		} catch (char * str){
			cout <<str <<endl;
			return -1;
		}
	}

	T peek(){
		try{
			if (_size == 0)
				throw "The stack is empty";
			return _stack->value;
		} catch(char * str){
			cout <<str <<endl;
			return -1;
		}
	}
};

int stackTest(){
	MyStack<double> s;
	s.push(1.2);
	double get = s.pop();
	cout <<get <<endl;
	cout <<s.size() <<endl;
	cin.get();
	cin.get();
	return 0;
}